package originala;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.*;

public class Dialogoa 
			extends JDialog 
			implements ActionListener, ItemListener
{

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;

	private JButton jButton1 = null;
	private JButton jButton2 = null;
	private JButton jButton3 = null;

	private JLabel jLabel1 = null;
	private JLabel jLabel2 = null;
	private JLabel jLabel3 = null;
	private JLabel jLabel4 = null;
	private JLabel jLabel5 = null;
	private JLabel jLabel6 = null;
	
	private JTextField jText1=null;
	private JTextField jText2=null;
	private JTextField jText3=null;
	private JTextField jText4=null;
	private JTextField jText5=null;
	private JTextField jText6=null;
	int count=1, baiZenb;
	private ErreserbaKontroladorea erreserbaKontroladorea=null;
	private ErreserbaSistema sistema = null;

	/**
	 * @param owner
	 */
	public Dialogoa(Frame owner, ErreserbaKontroladorea kontroladorea, ErreserbaSistema sistema, int baieztapenZenbakia) {
		super(owner);
		erreserbaKontroladorea=kontroladorea;
		baiZenb=baieztapenZenbakia;
		this.sistema = sistema;
		Toolkit tk = Toolkit.getDefaultToolkit();
        Dimension screenSize = tk.getScreenSize();
        int screenHeight = screenSize.height;
        int screenWidth = screenSize.width;
        this.setLocation(screenWidth / 4, screenHeight / 8);
		initialize();
		setVisible(true);
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(600, 400);
		this.setModal(true);
		this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		this.setContentPane(getJContentPane());
		
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jButton1 = new JButton();
			jButton1.setText("Onartu");
			jButton2 = new JButton();
			jButton2.setText("Hurrengo Turista");
			jButton3 = new JButton();
			jButton3.setText("Ezeztatu");
			if(erreserbaKontroladorea.getTuristaKop()==1)
			{
				jButton1.setEnabled(true);
				jButton2.setEnabled(false);
			}
			else
			{
				jButton1.setEnabled(false);
			}
			jLabel1 = new JLabel();
			jLabel1.setText("NAN");
			jLabel1.setHorizontalAlignment(JTextField.RIGHT);
			jLabel2 = new JLabel();
			jLabel2.setText("Izena");
			jLabel2.setHorizontalAlignment(JTextField.RIGHT);
			jLabel3 = new JLabel();
			jLabel3.setText("Abizena");
			jLabel3.setHorizontalAlignment(JTextField.RIGHT);
			jLabel4 = new JLabel();
			jLabel4.setText("Helbidea");
			jLabel4.setHorizontalAlignment(JTextField.RIGHT);
			jLabel5 = new JLabel();
			jLabel5.setText("Telefonoa");
			jLabel5.setHorizontalAlignment(JTextField.RIGHT);
			jLabel6 = new JLabel();
			jLabel6.setText("Txartel Zenbakia");
			jLabel6.setHorizontalAlignment(JTextField.RIGHT);
			jText1 = new JTextField();
			jText2 = new JTextField();
			jText3 = new JTextField();
			jText4 = new JTextField();
			jText5 = new JTextField();
			jText6 = new JTextField();
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.setLayout(new GridLayout(7, 3, 25, 25));
			jContentPane.setBackground(Color.lightGray);
			jContentPane.setBorder(BorderFactory.createEmptyBorder(25, 25, 25, 25));
			//1 errenkada
			jContentPane.add(jLabel1);
			jContentPane.add(jText1);
			jContentPane.add(new JLabel("          "));
			//2. errenkada
			jContentPane.add(jLabel2);
			jContentPane.add(jText2);		
			jContentPane.add(new JLabel("          "));
			//3
			jContentPane.add(jLabel3);
			jContentPane.add(jText3);
			jContentPane.add(new JLabel("          "));
			//4
			jContentPane.add(jLabel4);
			jContentPane.add(jText4);
			jContentPane.add(new JLabel("          "));
			//5
			jContentPane.add(jLabel5);
			jContentPane.add(jText5);
			jContentPane.add(new JLabel("          "));
			//6
			jContentPane.add(jLabel6);
			jContentPane.add(jText6);
			jContentPane.add(new JLabel("          "));
			//7
			jContentPane.add(jButton1);
			jContentPane.add(jButton2);
			jContentPane.add(jButton3);
			// Gehitu  event listener-ak
		    jButton1.addActionListener(this);
		    jButton2.addActionListener(this);
		    jButton3.addActionListener(this);
		}
		return jContentPane;
	}

	public void actionPerformed(ActionEvent e) 
	{
		if (e.getSource() == jButton1)//ACEPTAR
		{
			sistema.sartuTurista(jText1.getText(), jText2.getText(), jText3.getText(), jText4.getText(), jText5.getText(), baiZenb);
			if (count==1)
				sistema.sartuOrdaintzailea(jText1.getText(), jText2.getText(), jText3.getText(), jText4.getText(), jText5.getText(),  baiZenb,jText6.getText());
			sistema.turistakSartu();
			erreserbaKontroladorea.botoiaErreserbaBerria.setEnabled(false);
			erreserbaKontroladorea.botoiaSartuIrteera.setEnabled(false);
			erreserbaKontroladorea.botoiaSartuTurista.setEnabled(false);
			erreserbaKontroladorea.botoiaSartuBidali.setEnabled(true);
			erreserbaKontroladorea.botoiaSartuEzeztatu.setEnabled(true);
			dispose();
		}
		if (e.getSource() == jButton2)//HURRENGOA
		{
			if (count==1)
				sistema.sartuOrdaintzailea(jText1.getText(), jText2.getText(), jText3.getText(), jText4.getText(), jText5.getText(),  baiZenb,jText6.getText());
			
			sistema.sartuTurista(jText1.getText(), jText2.getText(), jText3.getText(), jText4.getText(), jText5.getText(), baiZenb);
			count++;
			jText6.setVisible(false);
			jLabel6.setVisible(false);
			if(count==erreserbaKontroladorea.getTuristaKop())
			{
				jButton1.setEnabled(true);
				jButton2.setEnabled(false);
				jText1.setText("");jText2.setText("");jText3.setText("");jText4.setText("");jText5.setText("");				
			}
			else
			{
				jText1.setText("");jText2.setText("");jText3.setText("");jText4.setText("");jText5.setText("");
			}
			
		}
		if (e.getSource() == jButton3)//CANCELAR
		{
			erreserbaKontroladorea.botoiaErreserbaBerria.setEnabled(false);
			erreserbaKontroladorea.botoiaSartuIrteera.setEnabled(false);
			erreserbaKontroladorea.botoiaSartuTurista.setEnabled(true);
			erreserbaKontroladorea.botoiaSartuBidali.setEnabled(false);
			erreserbaKontroladorea.botoiaSartuEzeztatu.setEnabled(false);
			dispose();
		}
		
	}

	public void itemStateChanged(ItemEvent arg0) {
		
	}


}
